package com.syf.controller.RJController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.syf.domain.store.BsCompanyApply;
import com.syf.domain.store.BsFeedback;
import com.syf.model.R;
import com.syf.service.BsFeedbackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author syf
 * @create 2022-02-08 9:26
 */
@RestController
@RequestMapping("/feedback")
@Api(tags = "用户反馈")
public class BsFeedbackController {

    @Autowired
    private BsFeedbackService feedbackService;

    @ApiOperationSupport(order = 1)   //该接口排在最前边
    @PostMapping("/before/addFeedback")
    @CrossOrigin
    @ApiOperation(value = "新增一个反馈")
    public R addFeedback(@RequestBody @Validated BsFeedback bsFeedback){
        boolean save = feedbackService.save(bsFeedback);
        if(save){
            return R.ok("新增成功") ;
        }
        return  R.fail("新增失败") ;
    }


 /*
【1】软件反馈列表：
{
    "current": 0,
    "size": 200,
    "feedbackType":"0",         //反馈类型（0软件反馈，1平台反馈）
    "softwareCode": "qq",       //软件代号(唯一标识)
    "manageStatus": 0,          //反馈状态（0等待处理，1已处理）
    "problemType": ""           //问题类型
}

【2】平台反馈列表：
{
    "current": 0,
    "size": 200,
    "feedbackType":"1",         //反馈类型（0软件反馈，1平台反馈）
    "manageStatus": 0,          //反馈状态（0等待处理，1已处理）
    "problemType": ""           //问题类型
}
  */

    @PostMapping("/feedbackList")
    @CrossOrigin
    @ApiOperation(value = "分页条件查询--反馈用户列表【反馈问题类型，反馈处理的状态】")
    public R<Page<BsFeedback>> findByPage(@RequestBody @Validated BsFeedback bsFeedback){
        Page<BsFeedback> pageData =  feedbackService.findByPage(bsFeedback) ;
        return R.ok(pageData) ;
    }





   /* @PostMapping("/feedbackDetails")
    @ApiOperation(value = "查看反馈用户详细")
    public R<BsFeedback> feedbackDetails(@RequestBody Integer id){
        BsFeedback bsFeedback =  feedbackService.getById(id) ;
        return R.ok(bsFeedback) ;
    }


    @PostMapping("/handleFeedback")
    @ApiOperation(value = "处理用户反馈(id,RelationType,msg,subject  /  id,ManageStatus)")
    public R handleFeedback(@RequestBody BsFeedback bsFeedback){
        if(bsFeedback.getRelationType().length() == 11){  //是电话
            return  R.fail("用户填写的联系方式为电话号码，请通话反馈");
        }
        boolean handle;
        if(bsFeedback.getManageStatus() == 1){ //点击已反馈
            handle =  feedbackService.updateById(bsFeedback);
        }else {
            //QQ邮箱反馈
            handle =  feedbackService.handleFeedback(bsFeedback);
        }

        if(handle){
            return R.ok("反馈成功") ;
        }
        return  R.fail("反馈失败") ;
    }
*/

}
